import { BasicColumn, FormSchema } from '/@/components/Table';
import { getDictDetailListApi } from '/@/api/sys/dict';
import { DataStatusEnum, UserTypeEnum } from '/@/enums/sysEnum';
import { getOrgTreeApi } from '/@/api/sys/org';


// 权限标识
export const Permission = {
    ADD: 'user.add',
    EDIT: 'user.edit',
    DEL: 'user.del',
};

// 定义表格列
export const columns: BasicColumn[] = [
    {
        title: '登录名称',
        dataIndex: 'loginName',
    },
    {
        title: '姓名',
        dataIndex: 'name',
    },
    {
        title: '手机号码',
        dataIndex: 'phone',
    },
    {
        title: '用户类型',
        dataIndex: 'userType',
    },
    {
        title: '锁定状态',
        dataIndex: 'lockStatus',
    },
    {
        title: '锁定原因',
        dataIndex: 'lockReason',
    },
    {
        title: '上次登录时间',
        dataIndex: 'lastLoginAt',
    },
    {
        title: '描述信息',
        dataIndex: 'remark',
    },
];

// 定义搜索列
export const searchFormSchema: FormSchema[] = [
    {
        field: 'loginName',
        label: '登录名称',
        component: 'Input',
        colProps: { span: 6 },
    },
    {
        field: 'name',
        label: '姓名',
        component: 'Input',
        colProps: { span: 6 },
    },
    {
        field: 'phone',
        label: '手机号码',
        component: 'Input',
        colProps: { span: 6 },
    },
    {
        field: 'lockStatus',
        label: '锁定状态',
        component: 'ApiSelect',
        componentProps: {
            api: getDictDetailListApi,
            params: {
                code: 'data_status',
            },
        },
        colProps: { span: 6 },
    },
];

// 定义新增、修改表单列
export const formSchema: FormSchema[] = [
    {
        field: 'divider-basic',
        component: 'Divider',
        label: '基础信息',
        colProps: {
            span: 24,
        },
    },
    {
        field: 'loginName',
        label: '登录名称',
        component: 'Input',
        rules: [
            { required: true, message: '请填写登录名称' },
            { max: 100, message: '登录名称最多100字' },
        ],
    },
    {
        field: 'name',
        label: '姓名',
        component: 'Input',
        rules: [
            { required: true, message: '请填写姓名' },
            { max: 100, message: '姓名最多100字' },
        ],
    },
    {
        field: 'phone',
        label: '手机号码',
        component: 'Input',
        rules: [
            { max: 100, message: '手机号码最多100字' },
        ],
    },
    {
        field: 'password',
        label: '登录密码',
        component: 'InputPassword',
        rules: [
            { required: true, message: '请填写登录密码' },
            { max: 100, message: '登录密码最多100字' },
        ],
    },
    {
        field: 'lockStatus',
        label: '锁定状态',
        component: 'ApiRadioGroup',
        componentProps: {
            api: getDictDetailListApi,
            params: {
                code: 'data_status',
            },
            isBtn: true,
        },
        defaultValue: DataStatusEnum.NORMAL,
    },
    {
        field: 'userType',
        label: '用户类型',
        component: 'ApiRadioGroup',
        componentProps: {
            api: getDictDetailListApi,
            params: {
                code: 'user_type',
            },
            isBtn: true,
        },
        defaultValue: UserTypeEnum.SYS,
    },
    {
        field: 'remark',
        label: '描述信息',
        component: 'InputTextArea',
        rules: [
            { max: 255, message: '描述信息最多255字' },
        ],
        colProps: { span: 4 },
    },
    {
        field: 'divider-permission',
        component: 'Divider',
        label: '权限设置',
        colProps: {
            span: 24,
        },
    },
    {
        field: 'orgId',
        component:"TreeSelect",
        label: "选择机构",
        componentProps: {
            fieldNames: {
                key: 'key',
                value: 'key',
                label: 'title',
                children: 'children',
            },
            treeDefaultExpandAll: true,
            getPopupContainer: () => document.body,
        },
        rules:[{required:true,message:'请选择组织机构'}]
    },
    {
        field: 'roleId',
        component:"TreeSelect",
        label: "选择角色",
        componentProps: {
            fieldNames: {
                key: 'roleId',
                value: 'roleId',
                label: 'name',
            }
        },
        rules:[{required:true,message:'请选择角色'}]
    }
];
